package com.up.mongo.config;

import com.alibaba.cloud.nacos.NacosConfigManager;
import com.mongodb.client.MongoClient;
import com.up.mongo.properties.AutoCreateIndexProperties;
import org.springframework.boot.autoconfigure.AutoConfigureAfter;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.autoconfigure.mongo.MongoProperties;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.mongodb.core.MongoTemplate;

@Configuration(proxyBeanMethods = false)
@ConditionalOnProperty(prefix = "mongodb.index.auto", value = "enable", havingValue = "true")
@AutoConfigureAfter(MongoAssemblyConfiguration.class)
@ConditionalOnClass(MongoClient.class)
@EnableConfigurationProperties({MongoProperties.class, AutoCreateIndexProperties.class})
public class MongoIndexesConfiguration {
    @Bean
    public AutoCreateIndexesManager autoCreateIndexesManager(MongoTemplate mongoTemplate, NacosConfigManager nacosConfigManager, AutoCreateIndexProperties indexProperties) {
        return new AutoCreateIndexesManager(nacosConfigManager,mongoTemplate,indexProperties);
    }


}
